package question0;


public class SynchronizedMemberMethod implements Runnable {
    // 这是购票的总票数
    private int trainCount = 5;

    @Override
    public void run() {
        if (trainCount > 0) {
            sale();
        }
    }

    // 同步方法
    public synchronized void sale() {
        if (trainCount > 0) {
            System.out.println(Thread.currentThread().getName() + ",出售 第" + (5 - trainCount + 1) + "张票.");
            trainCount--;
        }
    }

}